require("slog")

local Blocked = {
	"physics_constraints",
	"physics_debug_entity",
	"physics_select",
	"physics_budget",
	"sv_soundemitter_flush",
	"sv_soundscape_printdebuginfo",
	"vehicle_flushscript"
}

local DontShow = {
	"say",
	"dr_",
	"st_",
	"rp_",
	"rs_",
	"gms_",
	"status",
	"kill",
	"myinfo",
	"phys_swap",
	"+ass_menu",
	"-ass_menu",
	"explode",
	"feign_death",
	"gm_showhelp",
	"gm_showteam",
	"gm_showspare1",
	"gm_showspare2",
	"+gm_special",
	"-gm_special",
	"vban",
	"vmodenable",
	"se auth",
	"ulib_cl_ready",
	"noclip",
	"kill",
	"undo",
	"gmod_undo"
}

function Cmd_RecvCommand(name, buffer)
	print(name, buffer)

	local ply = nil
	
	for k,v in ipairs(player.GetAll()) do
		if IsValid(v) && v:Name() == name then
			ply = v
			break
		end
	end

	if !IsValid(ply) then
		return true
	end

	local clean = string.Trim(buffer)
	local lbuffer = string.lower(clean)

	for k,v in ipairs(DontShow) do
		if string.sub(lbuffer, 1, string.len(v)) == v then
			return false
		end
	end

	local block = false

	for k,v in ipairs(Blocked) do
		if string.sub(lbuffer, 1, string.len(v)) == v then
			block = true
			break
		end
	end

	local name, steam = "UNKNOWN", "UNKNOWN"

	if IsValid(ply) then
		name, steam = ply:Name(), ply:SteamID()
	end

	local log = string.format("[%s] %s (%s) Ran: %s\n", os.date("%c"), name, steam, clean)

	AppendLog(string.gsub(steam, ":", "_"), log)

	if blocked then
		AppendLong("Blocked", log)
	end

	return block
end